<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>

    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
</head>

<body>
<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="proDetail" class="layui-form-label"><span class="x-red">*</span>试题详情</label>
            <br>
            <div class="layui-card-body layui-row layui-col-space10">
                <div class="layui-col-md12">
                    <textarea name="proDetail" class="layui-textarea" id="proDetail"></textarea>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="proAnsno" class="layui-form-label"><span class="x-red">*</span>试题答案</label>
            <br>
            <div class="layui-card-body layui-row layui-col-space10">
                <div class="layui-col-md12">
                    <input type="text" readonly="readonly" id="proAnsno" name="proAnsno" value=""
                           autocomplete="off" class="layui-input" style="width: 500px">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="proKey" class="layui-form-label">试题关键字</label>
            <div class="layui-input-inline">
                <input type="text" id="proKey" name="proKey" value=""
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="proDif" class="layui-form-label"><span class="x-red">*</span>试题难度</label>
            <div class="layui-input-inline">
                <select name="contrller" id="proDif">
                    <option value="">难易程度</option>
                    <option value="easy">easy</option>
                    <option value="normal">normal</option>
                    <option value="hard">hard</option>
<!--                    <option value="3" selected>这里原来的内容</option>     select这是修改默认显示的格式，你可以看看怎么修改-->
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="chaNo" class="layui-form-label">章节号</label>
            <div class="layui-input-inline">
                <input type="text" id="chaNo" name="chaNo" value=""
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="chaName" class="layui-form-label">章节名称</label>
            <div class="layui-input-inline">
                <input type="text" id="chaName" name="chaName" value=""
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="chaMpoint" class="layui-form-label">章节要点</label>
            <div class="layui-input-inline">
                <input type="text" id="chaMpoint" name="chaMpoint" value=""
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="proType" class="layui-form-label">试题类型</label>
            <div class="layui-input-inline">
                <input type="text" id="proType" name="proType" value=""
                       autocomplete="off" class="layui-input" style="width: 500px">
            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button  class="layui-btn layui-btn-warm" lay-filter="add" lay-submit="" onclick="changePro()">
                修改
            </button>
        </div>
    </form>
</div>
<script>


    var content=parent.$('#Id').val();
    console.log(content);
    var proAnsno;
    $.ajax({
        url: "/library/getprobyno",
        type : "post",
        async: false,
        dataType: "json",
        data : {proNo: content},
        //contentType :"application/json",
        success: function (data) {
            console.log("请求成功");
            console.log(data);
            $("#proDetail").val(data.proDetail);
            proAnsno=data.proAnsno;
            $.ajax({
                url: "/library/getanswerbyproansno",
                type : "post",
                async: false,
                dataType: "json",
                data : {proAnsno:proAnsno},
                //contentType :"application/json",
                success: function (data) {
                    console.log("请求成功");
                    console.log(data);
                    $("#proAnsno").val(data.ansDetail);
                },
                error: function (data) {
                    console.log("请求失败");
                }
            });

            $("#proKey").val(data.proKeyw);

            $("#chaNo").val(data.chaNo);
            $("#chaName").val(data.chaTitle);
            $("#chaMpoint").val(data.proDetail);
            $("#proType").val(data.proType);
        },
        error: function (data) {
            console.log("请求失败");
        }
    });

    function changePro(){
        console.log("成功开始修改题目");
        var proDetail = $("#proDetail").val();
        var proKeyw = $("#proKey").val();
        var proDif = $("#proDif").val();
        var chaNo = $("#chaNo").val();
        var chaTitle = $("#chaName").val();
        var chaMpoint = $("#chaMpoint").val();
        var proType = $("#proType").val();
        var proNo = content;

        var problem = {proNo:proNo ,proDetail:proDetail,proAnsno:proAnsno,proKeyw:proKeyw,proDif:proDif,
            chaNo:chaNo,chaTitle:chaTitle,chaMpoint:chaMpoint,proType:proType,teaNo:null};

        console.log(JSON.stringify(problem));

        $.ajax({
            url: "/library/editproblem",
            type : "post",
            async: false,
            dataType: "json",
            data :JSON.stringify(problem),
            contentType :"application/json",
            success: function (data) {
                console.log("请求成功");
                console.log(data);
                if(data === 1) {alert("修改成功，刷新以显示新的信息");
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);}
                if(data === 0)
                {
                    alert("添加失败");
                }
                return;
            },
            error: function (data) {
                console.log("请求失败");

            }
        });
    }

</script>
</body>

</html>